package com.jsnkj.basic.fragment

import androidx.lifecycle.MutableLiveData
import com.jsnkj.basic.bean.ErrorEntity
import com.jsnkj.basic.bean.InviteCodeEntity
import com.jsnkj.basic.bean.PopularizeSummaryEntity
import com.jsnkj.basic.bean.UserLoginEntity
import com.jsnkj.basic.http.HttpApiService
import com.jsnkj.basic.mvvm.HttpViewModel
import com.yang.http.HttpRequest

class InviteFriendsViewModel : HttpViewModel() {

    var loginEntityResult: MutableLiveData<UserLoginEntity> = MutableLiveData()

    var postHttpResult: MutableLiveData<InviteCodeEntity> = MutableLiveData()

    var errorResult: MutableLiveData<ErrorEntity> = MutableLiveData()

    /**
     * 推广
     */
    fun postUserInviteCode() {
        launchHttp({
            HttpRequest.getService(HttpApiService::class.java).postUserInviteCode()
        }, onResult = { it ->
            com.jsnkj.basic.util.LogUtils.e("请求成功：$it")
            postHttpResult.value = it
        }, onFailed = { code, msg ->
            errorResult.value = ErrorEntity.getInstance(code, msg)
        }) {
        }
    }


    var postPopularizeResult: MutableLiveData<PopularizeSummaryEntity> = MutableLiveData()

    /**
     * 推广
     */
    fun postPopularizeSummary() {
        launchHttp({
            HttpRequest.getService(HttpApiService::class.java).postPopularizeSummary()
        }, onResult = { it ->
            com.jsnkj.basic.util.LogUtils.e("请求成功：$it")
            postPopularizeResult.value = it
        }, onFailed = { code, msg ->
            errorResult.value = ErrorEntity.getInstance(code, msg)
        }) {
        }
    }
}